//
// Created by zhupi on 2024/9/5.
//

#include "main_window.h"
#include "toolbar_widget.h"
#include <QMenuBar>
#include <QToolBar>
#include <QWidgetAction>

#include "main_window_file.h"
#include <QDockWidget>
#include "main_window_buttom.h"
#include "project_dock.h"
#include "center_window.h"
#include "message_dock.h"
#include "message_tree.h"
#include "dock_tab_widget.h"


#include <QTextEdit>


MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
{
    // 创建菜单栏
    MainWindowMenuBar *menuBar = new MainWindowMenuBar(this);
    menuBar->Initial();
    setMenuBar(menuBar);

    // 创建工具栏
    QToolBar *toolBar = new QToolBar(this);
    addToolBar(Qt::TopToolBarArea, toolBar);
    // 设置工具栏的样式
    toolBar->setMovable(false);  // 禁用工具栏的抓手


    // 创建自定义的工具栏Widget
    MainWindowToolBarWidget *customWidget = new MainWindowToolBarWidget(this);
    customWidget->InitIal();
    // 将自定义Widget放到QWidgetAction中
    QWidgetAction *widgetAction = new QWidgetAction(this);
    widgetAction->setDefaultWidget(customWidget);
    // 添加到工具栏
    toolBar->addAction(widgetAction);

    // 设置中心窗口
    InitCenterWidget();

    // 设置侧边栏
    InitDock();

    // 底部的状态栏
    InitButtom();

}

MainWindow::~MainWindow()
{
}

void MainWindow::InitButtom() {
    MainWindowButtom * buttom  =new MainWindowButtom(this);
    buttom->Initial();
    this->setStatusBar(buttom);
}

void MainWindow::InitDock()
{
    ProjectDock *projectDock = new ProjectDock(this);
    projectDock->Initial();
    this->addDockWidget(Qt::LeftDockWidgetArea, projectDock);

    //
    PropertiesTabWidget *propertiesTabWidget = new PropertiesTabWidget(this);
    propertiesTabWidget->Initial();
    this->addDockWidget(Qt::LeftDockWidgetArea, propertiesTabWidget);

    // message
    MessageDock *messageWindow = new MessageDock(this);
    messageWindow->Initial();
//    messageWindow->setMinimumHeight(300);
    this->addDockWidget(Qt::BottomDockWidgetArea, messageWindow);

    MessageTree *messageTree = new MessageTree(this);
    messageTree->Initial();
    this->addDockWidget(Qt::BottomDockWidgetArea, messageTree);
}



void MainWindow::InitCenterWidget() {
    CenterWindow *center = new CenterWindow(this);
    center->Initial();
    this->setCentralWidget(center);
}

